//
//  FlowFormViewController.m
//  CQWU_OA
//
//  Created by WisdomsLab on 14-1-16.
//  Copyright (c) 2014年 Juchui. All rights reserved.
//

#import "FlowFormViewController.h"
#import "UIHelper.h"
#import "PersonalPicker.h"

@interface FlowFormViewController ()<
UITextFieldDelegate,
PersonalPickerDelegate>

@end

@implementation FlowFormViewController

@synthesize nodeTag;

@synthesize nodeLabel;
@synthesize personalText;
@synthesize departmentText;
@synthesize noticeText;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    nodeLabel.text = [NSString stringWithFormat:@"下一步:拟稿%@",nodeTag];
    if([nodeTag integerValue]%2 == 0){
        departmentText.hidden = YES;
    }
    
    personalText.delegate = self;
    
    UIBarButtonItem *sendItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(sendAction:)];
    self.navigationItem.rightBarButtonItem = sendItem;
}

-(void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
    [super viewWillAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    PersonalPicker *picker = (PersonalPicker *)[self.storyboard instantiateViewControllerWithIdentifier:@"PersonalPicker"];
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:nil];
    return NO;
}

#pragma mark - PersonalPickerControllerDelegate
-(void)personalPickerController:(PersonalPicker *)picker didFinishPickingWithInfo:(NSArray *)info{
    [picker dismissViewControllerAnimated:YES completion:^{
        NSMutableString *str = [[NSMutableString alloc] initWithCapacity:0];
        
        for(NSDictionary *dic in info){
            [str appendFormat:@"%@,",dic[@"name"]];
        }
        
        personalText.text = str;
        [personalText resignFirstResponder];
    }];
}

-(void)personalPickerControllerDidCancel:(PersonalPicker *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - Actions
-(void)sendAction:(id)sender{
    [UIHelper showHudWithDuration:@"任务完成!" :3.0f];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

@end
